__author__ = 'Jerry Liu'
import socket
from time import  ctime

HOST = '127.0.0.1'
PORT = 1234

ADDR = (HOST, PORT)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(ADDR)
s.listen(1)
conn, addr = s.accept()
print('connect by', addr)

while True:
    data = conn.recv(1024).decode()
    print('by:', data)
    if not data:
        break
    elif data == 'time':
        conn.send(ctime().encode())
    elif data == 'how are you':
        conn.send(str('I am fine.').encode())
    else:
        conn.send(str('...').encode())
conn.close()
s.close()